#include <stdio.h>
#include <string.h>
#include "ut.h"

extern TestDesc ll_tests[];
extern TestDesc attr_tests[];

typedef struct {
    const char *desc;
    TestDesc   *test_list;
} SuiteDesc;

SuiteDesc suites[] = {
    { "ll", ll_tests },
    { "attributes", attr_tests },
};
    
int total = 0;
int failures = 0;

int main()
{
    int i, j;
    TestDesc *td;

    total = 0;
    failures = 0;

    for (i=0; i < sizeof(suites) / sizeof(SuiteDesc); i++) {
        printf("running %s suite\n", suites[i].desc);
        
        for (j=0; suites[i].test_list[j].fun != NULL; j++) {
            td = &suites[i].test_list[j];
            printf("   test %s\n", td->desc);
            td->fun();
        }
    }

    int pass = (total - failures);
    printf("\n");
    printf("Passed: %d/%d (%d%%)\n", pass, total, (pass*100/total));
    printf("Failed: %d/%d (%d%%)\n", failures, total, (failures*100/total));
    if (failures) printf("FAILED\n");
    printf("\n");

    if (failures) return 1;
    return 0;
}



int _ASSERT(int cond, const char *what) {
    total++;
    if (!cond) {
        failures++;
        printf("FAIL: %s\n", what);
        return -1;
    }

    return 0;
}

int _ASSERT_EQI(int is, int should, const char *what) {
    total++;

    if (is != should) {
        failures++;
        printf("FAIL: %s, %d should be %d\n", what, is, should);
        return -1;
    }

    return 0;
}

int _ASSERT_EQS(const char *is, const char *should, const char *what) {
    total++;

    if (strcmp(is, should) != 0) {
        failures++;
        printf("FAIL: %s, '%s' should be '%s'\n", what, is, should);
        return -1;
    }

    return 0;
}


